mini.parse();
function MemberFormHandlerc() {
};

try {
	MemberFormHandlerc.memberForm = new mini.Form("memberForm");
} catch (e) {
}

var data = [{
			id : "0",
			text : "否"
		}, {
			id : "1",
			text : "是"
		}];

var dataState = [{
			id : "-1",
			text : "全部"
		}, {
			id : "0",
			text : "未激活"
		}, {
			id : "1",
			text : "已激活"
		}, {
			id : "2",
			text : "冻结"
		}, {
			id : "3",
			text : "删除"
		}];
		
try {
	var bmbSmnotify = mini.get("bmbSmnotify");
	bmbSmnotify.loadData(data);
	bmbSmnotify.setValue("1");
} catch (e) {
}

try {
	var bmbEmnotify = mini.get("bmbEmnotify");
	bmbEmnotify.loadData(data);
	bmbEmnotify.setValue("1");
} catch (e) {
}

try {
	var bmbState = mini.get("bmbState");
	bmbState.load(dataState);
	bmbState.setValue("-1");
} catch (e) {
}

MemberFormHandlerc.addMember = function() {
	miniWin.afreshNewWin();
	miniWin.setParams(598, 270, "添加会员");
	miniWin.setOption("allowResize", true);
	miniWin.setOption("bodyStyle", "padding:0px;");

	miniWin.load("memberFormTag.jsp", function() {
			}, function(action) {
				new mini.get("memberGrid").reload();
			});
	miniWin.show();
};

MemberFormHandlerc.delMember = function() {
	var rowsData = mini.get("memberGrid").getSelecteds();
	if (rowsData.length > 0) {
		mini.confirm("确定删除选择的" + rowsData.length + "条记录？", "确定？", function(
						action) {
					if (action == "ok") {
						var ts = "";
						for (var i = 0; i < rowsData.length; i++)
							ts += "'" + rowsData[i].bmbId + "',";
						mini.get("memberGrid").loading();
						
						$.ajax({
									url : "../../../delMember.do",
									type : "POST",
									data : {
										bmbIdlist : ts,
							        	lslUser: gbOperateUser,
							    		lslAddress: gbOperateIp
									},
									cache : false,
									success : function(text) {
										mini.get("memberGrid").unmask();
										MiniuiTools.miniInfo("系统提示", "操作成功！",
												function() {
													mini.get("memberGrid")
															.reload();
												});
									},
									error : function(jqXHR, textStatus, errorThrown) {
										mini.alert(jqXHR.responseText, "系统提示", null);
									}
								});
					}
				});

	} else {
		mini.alert("请选择要编辑的资源！", "系统提示", null);
	}
};

MemberFormHandlerc.editMember = function() {
	var rowsData = mini.get("memberGrid").getSelecteds();
	if (rowsData.length == 1) {
		miniWin.afreshNewWin();
		miniWin.setParams(598, 270, "编辑会员");
		miniWin.setOption("bodyStyle", "padding:0px;");

		miniWin.load("memberFormTag.jsp", function() {
					var iframe = miniWin.getIFrameEl();
					iframe.contentWindow.MemberFormHandlerc.setDataTab(rowsData[0]);
				}, function(action) {
					new mini.get("memberGrid").reload();
				});

		miniWin.show();
	} else if (rowsData.length > 1) {
		mini.alert("不能同时编辑多条资源！", "系统提示", null);
	} else {
		mini.alert("请选择要编辑的资源！", "系统提示", null);
	}
};

MemberFormHandlerc.isQueryBtnExpended = false;
MemberFormHandlerc.queryShow = function() {
	if (MemberFormHandlerc.isQueryBtnExpended) {
		MemberFormHandlerc.isQueryBtnExpended = false;
		mini.get("member_list_query").setText("展开查询");
		mini.get("member_list_query").setIconCls("icon-btn-expand");
	} else {
		MemberFormHandlerc.isQueryBtnExpended = true;
		mini.get("member_list_query").setText("收起查询");
		mini.get("member_list_query").setIconCls("icon-btn-collapse");
	}
	
	$("#queryMemberDiv").toggle(500);
	setTimeout(function() {
				mini.get("memberPanel").doLayout();
			}, 600);
};

MemberFormHandlerc.setDataTab = function(json) {
	json.bmbIntegral = json.bmbIntegral.toString();
	
	MemberFormHandlerc.memberForm.setData(json);
};

MemberFormHandlerc.freezeMember = function() {
	var rowsData = mini.get("memberGrid").getSelecteds();
	
	if (rowsData.length > 0) {
		mini.confirm("确定冻结记录？", "确定？", function(action) {
					if (action == "ok") {
						var ts = "";
						for (var i = 0; i < rowsData.length; i++)
							ts += "'" + rowsData[i].bmbId + "',";
						$.ajax({
									url : "../../../operateMember.do?type=2",
									type : "POST",
									data : {
										bmbIdlist : ts,
							        	lslUser: gbOperateUser,
							    		lslAddress: gbOperateIp
									},
									cache : false,
									success : function(text) {
										new mini.get("memberGrid").reload();

									},
									error : function(jqXHR, textStatus, errorThrown) {
										mini.alert(jqXHR.responseText, "系统提示", null);
									}
								});

					}
				});
	} else {
		mini.alert("请选择冻结记录", "系统提示", null);
	}
};

MemberFormHandlerc.activateMember = function() {
	var rowsData = mini.get("memberGrid").getSelecteds();
	
	if (rowsData.length > 0) {
		mini.confirm("确定激活记录？", "确定？", function(action) {
					if (action == "ok") {
						var ts = "";
						for (var i = 0; i < rowsData.length; i++)
							ts += "'" + rowsData[i].bmbId + "',";
							
						$.ajax({
									url : "../../../operateMember.do",
									type : "POST",
									data : {
										type: 1,
										bmbIdlist : ts,
							        	lslUser: gbOperateUser,
							    		lslAddress: gbOperateIp
									},
									cache : false,
									success : function(text) {
										new mini.get("memberGrid").reload();
									},
									error : function(jqXHR, textStatus,errorThrown) {
										mini.alert(jqXHR.responseText, "系统提示",null);
									}
								});

					}
				});
	} else {
		mini.alert("请选择激活记录", "系统提示", null);
	}
};

/**
 * 保存（添加或编辑）数据的方法
 */
MemberFormHandlerc.save = function() {
	var MemberData = MemberFormHandlerc.memberForm.getData();
	MemberFormHandlerc.memberForm.validate();

	if (MemberFormHandlerc.memberForm.isValid() == false)
		return;

	var json = mini.encode(MemberData);

	$.ajax({
				url : "../../../saveOrUpdateMember.do",
				type : "POST",
				data : {
					MemberInfo : json,
					lslUser : gbOperateUser,
					lslAddress : gbOperateIp
				},
				cache : false,
				success : function(text) {
					MemberFormHandlerc.closeCurrentWin("save");
					// new mini.get("memberGrid").reload();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.alert(jqXHR.responseText, "系统提示", null);
					MemberFormHandlerc.closeCurrentWin();
				}
			});

};

/**
 * 关闭窗口
 * 
 * @param {}
 */
MemberFormHandlerc.closeCurrentWin = function(action) {
	if (window.CloseOwnerWindow)
		window.CloseOwnerWindow(action);
	else
		window.close();
};

MemberFormHandlerc.closeMiniWin = function() {
	MemberFormHandlerc.closeCurrentWin("cancel");
};
